<template>
  <div class="div_padding">
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline" size="small">
      <el-form-item label="请求模块:" prop="request_modular">
        <el-input v-model="formInline.request_modular" placeholder="请求模块"></el-input>
      </el-form-item>
      <el-form-item label="请求地址:" prop="request_path">
         <el-input v-model="formInline.request_path" placeholder="请求地址"></el-input>
      </el-form-item>
      <el-form-item label="请求方式:" prop="request_method">
         <el-select v-model="formInline.request_method" placeholder="请选择活动区域">
            <el-option label="GET" value="GET"></el-option>
            <el-option label="POST" value="POST"></el-option>
            <el-option label="PUT" value="PUT"></el-option>
            <el-option label="DELETE" value="DELETE"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="filterData">查询</el-button>
        <el-button icon="el-icon-refresh" plain @click="resetForm('formInline')">重置</el-button>
        <!-- <Insert ref="insert" @reloadTable="reloadTable"></Insert>
        <Edit ref="edit" @reloadTable="reloadTable"></Edit> -->
      </el-form-item>
      <el-button style="float: right" icon="el-icon-refresh-right" circle @click="reloadTable"></el-button>
    </el-form>
    <el-table
      :data="tableData"
      size="mini"
      height="72vh"
      v-loading="loading"
      empty-text="查询结果为空!"
      element-loading-text="数据加载中..."
      element-loading-spinner="el-icon-loading"
      style="width: 100%;overflow-x: hidden;"
      row-key="id"
      border>
      <el-table-column
        prop="id"
        label="ID"
        v-if="showId"
        align="center"
        width="180">
      </el-table-column>
      <el-table-column
        label="序号"
        align="center"
        type="index"
        width="50">
      </el-table-column>
      <el-table-column
        prop="request_modular"
        label="请求模块"
        align="center"
        width="150">
      </el-table-column>
      <el-table-column
        prop="request_path"
        label="请求地址"
        align="center"
        width="180">
      </el-table-column>
      <el-table-column
        prop="request_method"
        label="请求方法"
        align="center"
        width="120">
      </el-table-column>
      <el-table-column
        prop="request_ip"
        label="ip地址"
        align="center"
        width="120">
      </el-table-column>
      <el-table-column
        prop="request_browser"
        label="请求浏览器"
        align="center"
        width="180">
      </el-table-column>
      <el-table-column
        prop="response_code"
        label="响应码"
        align="center"
        width="120">
      </el-table-column>
      <el-table-column
        prop="json_result"
        label="返回信息"
        align="center"
        width="150">
      </el-table-column>
      <el-table-column
        prop="creator_name"
        label="操作人"
        align="center"
        width="150">
      </el-table-column>
      <el-table-column
        prop="create_datetime"
        label="操作时间"
        align="center"
        >
      </el-table-column>
    </el-table>
    <div class="block" style="margin: 5px;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      background
      :current-page="cur_page"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </div>
  </div>
</template>
<script>
  import { getOperationLogData } from '@/api/operation_log'
  import { successMsg } from '@/utils/tools'
//   import Insert from './insert'
//   import Edit from './edit'
  export default {
    name:'Loginlog',
    // components:{
    //   Insert,
    //   Edit
    // },
    data() {
      return {
        showId:false,
        loading:true,
        tableData: [],
        total:0,
        cur_page:1,
        pageSize:10,
        formInline: {
          request_modular: '',
          request_path: '',
          request_method:''
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getOperationLogData({'page':this.cur_page,'limit':this.pageSize}).then(res=>{
          this.tableData=res.data.data
          this.total = res.data.total
          this.loading=false
        })
      },
      reloadTable(){
        this.loading=true
        this.fetchData()
      },
      filterData(){
        let params = {}
        if(this.formInline.request_modular){
          params.request_modular=this.formInline.request_modular
        }
        if(this.formInline.request_path){
          params.request_path=this.formInline.request_path
        }
        if(this.formInline.request_method){
          params.request_method=this.formInline.request_method
        }
        params.page=this.cur_page
        params.limit=this.pageSize
        this.loading=true
        getOperationLogData(params).then(res=>{
          this.tableData=res.data.data
          this.total=res.data.total
          this.loading=false
        })
      },
      resetForm(formName){
        this.$refs[formName].resetFields()
        this.reloadTable()
      },
      handleSizeChange(val) {
        this.pageSize=val
        this.loading=true
        this.filterData()
      },
      handleCurrentChange(val) {
        this.cur_page=val
        this.loading=true
        this.filterData()
      },
    },
  }
</script>
<style lang="scss" scoped>
  .div_padding {
    padding: 10px 10px
  }
</style>
